package com.zhouheng.common.base.exception;

import com.zhouheng.common.base.BaseCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class SysErrorException extends RuntimeException {
    private static final int CODE_BASE = 0;
    private static int INCR = 0;

    public static final ErrorCode ERROR = ErrorCode.define(CODE_BASE + (INCR++), "系统异常");

    private ErrorCode error;

    public SysErrorException(ErrorCode error) {
        super(error.getMsg());
        this.error = error;
    }

    public SysErrorException(ErrorCode error, String message) {
        super(message);
        this.error = error;
    }

    public SysErrorException(String message) {
        super(message);
        this.error = ERROR;
    }


    /**
     * @author wuqianlun
     * @date 2021/6/29 13:37
     */
    public static class ErrorCode implements BaseCode {
        private int code;
        private String message;

        private ErrorCode(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public static ErrorCode define(int code, String message) {
            return new ErrorCode(code, message);
        }

        @Override
        public int getCode() {
            return code;
        }

        @Override
        public String getMsg() {
            return message;
        }
    }
}



